Goproxy.cn 您所在的位置:网站首页 a go go go go go go Goproxy.cn

Goproxy.cn

#Goproxy.cn| 来源: 网络整理| 查看: 265

Your code is always yours, so we provide you with the coolest self-hosted Go module proxy building solution in the world. By using Goproxy, a minimalist project, you can easily add Go module proxy support to any existing web service, you know that Goproxy.cn is built on it.

Create a file named goproxy.go

package main import ( "net/http" "os" "github.com/goproxy/goproxy" ) func main() { http.ListenAndServe("localhost:8080", &goproxy.Goproxy{ GoBinEnv: append( os.Environ(), "GOPROXY=https://goproxy.cn,direct", // Use Goproxy.cn as the upstream proxy "GOPRIVATE=git.example.com", // Solve the problem of pulling private modules ), ProxiedSUMDBs: []string{ "sum.golang.org https://goproxy.cn/sumdb/sum.golang.org", // Proxy the default checksum database }, }) }

and run it

$ go run goproxy.go

then try it by setting GOPROXY to http://localhost:8080. In addition, we also recommend that you set GO111MODULE to on.

That's it, a fully functional Go module proxy is successfully built. In fact, you can use Goproxy with your favorite web frameworks, such as Gin and Echo, all you need to do is add one more route. For more advanced usage please check the documentation.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有